$(function () {
    obj.init();
});

var obj = new function() {
    return {
        dataGrid: null,
        params: {
            schoolId: null
        },
        init: function () {
            this.params.schoolId = xhTool.getQuery('schoolId');

            this.dataGrid = new xhDataGrid($('#list'), 'School/getOtherUser', {schoolId: this.params.schoolId});
            this.dataGrid.parseToolbar().init().activeButton(['bt_list_refresh_login',  'bt_list_set_history', 'bt_list_set_normal'], []);
            xhExtra.clearLoadSuccess(this.dataGrid);

            xhTool.bindDocKeyDown($('#bt_list_search'));
            this.listener();
        },
        listener: function () {
            var $this = this;
            //绑定搜索事件
            $('#bt_list_search').click(function(){
                $this.funObj().search();
            });
            //刷新登陆
            $('#bt_list_refresh_login').click(function(){
                if(xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().refreshLogin();
            });
            //设为历史
            $('#bt_list_set_history').click(function () {
                if(xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().setHistory(true);
            });
            //设为正常
            $('#bt_list_set_normal').click(function () {
                if(xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().setHistory(false);
            });
        },
        funObj: function () {
            var $this = this;
            return {
                search: function () {
                    var params = {
                        search: {
                            vague: xhExtra.getValue($('#list_vague')),
                            items: xhExtra.getValue($('#list_items'))
                        },
                        history: xhExtra.getValue($('#list_history'))
                    };
                    $this.dataGrid.reload(params);
                },
                refreshLogin: function () {
                    xhExtra.ajaxRequest('School/refreshLoginInfo', {userIds: $this.dataGrid.getSelectValues('iUserId')}, {success: true, table: $this.dataGrid});
                },
                setHistory: function (history) {
                    xhExtra.askChangeStatus('User/setHistory', {ids: $this.dataGrid.getSelectValues('iUserId'), history: history}, $this.dataGrid, history ? '设置为历史？' : '设置为正常？');
                }
            }
        }
    }
};